package c1763;

import java.util.LinkedList;
import java.util.Scanner;

public class A {
    static Scanner cin = new Scanner(System.in);

    public static void main(String[] args) {
        while (cin.hasNext()) {
            int n = cin.nextInt();
            int m = cin.nextInt();
            LinkedList<Integer> L = new LinkedList<>();
            for (int i = 1; i <= n; i++) {
                L.add(i);
            }
            for (int i = 0, j = 0; i < n - 1; i++) {
                j = (j + m - 1) % L.size();
                L.remove(j);
            }
            System.out.println(L.getFirst());
        }
    }
}